package com.hansheng.action.tailing;

import com.alibaba.fastjson.JSONArray;
import com.hansheng.service.impl.SheetServiceImpl;
import com.hansheng.util.JsonHelper;
import com.hansheng.util.PrintWriterHelper;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by GoldenMan on 2017/5/18.
 */
public class GetOutFormListAction extends ActionSupport implements ServletResponseAware, ServletRequestAware {
    private SheetServiceImpl sheetService;
    private HttpServletResponse httpServletResponse;
    private HttpServletRequest httpServletRequest;

    public void setSheetService(SheetServiceImpl sheetService) {
        this.sheetService = sheetService;
    }

    @Override
    public void setServletRequest(HttpServletRequest request) {
        this.httpServletRequest = request;
    }

    @Override
    public void setServletResponse(HttpServletResponse response) {
        this.httpServletResponse = response;
        httpServletResponse.setContentType("text/html;charset=utf-8");
        httpServletResponse.setHeader("Cache-Control", "no-cache");
        httpServletResponse.setHeader("Access-Control-Allow-Origin", "*");
    }

    @Override
    public String execute() throws Exception {
        String whereHql="where o.status=?";
        Object[] params={0};
        JSONArray outFormArray=sheetService.getOutFormArrayByCondition(whereHql,params);
        PrintWriterHelper.send( JsonHelper.successJSONBuilder(outFormArray));
        return null;
    }
}
